//
//  CTCollectionViewSectionInfo.h
//
//  Created by Andney Jack on 2021/6/2.
//

#import <UIKit/UIKit.h>
#import "CTCollectionViewColumnLayoutDefines.h"
@class CTCollectionViewItemInfo;

struct CTItemBounds {
    CGFloat top, bottom;
};
typedef struct CG_BOXABLE CTItemBounds CTItemBounds;

CG_INLINE CTItemBounds CTItemBoundsMake(CGFloat top, CGFloat bottom)
{
    CTItemBounds bounds;
    bounds.top = top;
    bounds.bottom = bottom;
    return bounds;
}

@interface CTCollectionViewSectionInfo : NSObject

@property (nonatomic, assign) NSInteger section;
@property (nonatomic, assign) NSInteger columnCount;
@property (nonatomic, assign) CGFloat columnSpacing;
@property (nonatomic, assign) CGFloat interitemSpacing;
@property (nonatomic, assign) CGFloat collectionViewWidth;
@property (nonatomic, assign) CGFloat columnWidth;

@property (nonatomic, assign) CGFloat top;
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, assign) CGFloat footerHeight;

@property (nonatomic, assign) CTItemBounds headerBounds;
@property (nonatomic, assign) CTItemBounds footerBounds;
@property (nonatomic, assign) BOOL headerPinToVisible;
@property (nonatomic, assign) BOOL footerPinToVisible;

@property (nonatomic, assign) UIEdgeInsets headerInsets;
@property (nonatomic, assign) UIEdgeInsets footerInsets;
@property (nonatomic, assign) UIEdgeInsets sectionInsets;
@property (nonatomic, assign) UIEdgeInsets safeAreaInsets;

@property (nonatomic, assign) CTCollectionViewItemRenderDirection itemRenderDirection;

@property (nonatomic, strong) NSMutableArray<CTCollectionViewItemInfo *> *allItemInfos;
@property (nonatomic, strong) UICollectionViewLayoutAttributes *headerAttribute;
@property (nonatomic, strong) UICollectionViewLayoutAttributes *footerAttribute;

@property (nonatomic, assign, readonly) CGFloat totalSectionHeight; // height for header + items + footer
@property (nonatomic, assign, readonly) CGFloat sectionContentHeight; // height for items
@property (nonatomic, assign, readonly) CGFloat headerTotalHeight;
@property (nonatomic, assign, readonly) CGFloat footerTotalHeight;
@property (nonatomic, assign, readonly) CGFloat sectionBottom;

- (void)setNeedRecalculate;
- (void)recalculateIfNeeded;
- (BOOL)hasFloatingHeaderOrFooter;

@end

#pragma mark - ————————— CTCollectionViewItemInfo —————————

@interface CTCollectionViewItemInfo : NSObject

@property (nonatomic, assign) NSInteger section;
@property (nonatomic, assign) NSInteger item;
@property (nonatomic, assign) CGFloat itemWidth;
@property (nonatomic, assign) CGFloat itemHeight;
@property (nonatomic, assign) NSInteger columnIndex;

@property (nonatomic, copy) UICollectionViewLayoutAttributes *itemAttributes;

@end
